package com.eduagent.xwqeduagent.service;

import com.eduagent.xwqeduagent.api.TextCorrection.TextCorrectionClient;
import com.eduagent.xwqeduagent.api.TextCorrection.TextCorrectionResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 文本纠错服务
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class TextCorrectionService {
    
    private final TextCorrectionClient textCorrectionClient;
    
    /**
     * 执行文本纠错
     * @param text 需要纠错的文本
     * @return 纠错结果
     */
    public TextCorrectionResult correctText(String text) {
        return correctText(text, null, null);
    }
    
    /**
     * 执行文本纠错（带黑白名单）
     * @param text 需要纠错的文本
     * @param uid 用户ID
     * @param resId 资源ID
     * @return 纠错结果
     */
    public TextCorrectionResult correctText(String text, String uid, String resId) {
        try {
            log.info("开始进行文本纠错，文本长度：{}", text.length());
            TextCorrectionResult result = textCorrectionClient.correct(text, uid, resId);
            log.info("文本纠错完成");
            return result;
        } catch (IOException | InterruptedException e) {
            log.error("文本纠错失败", e);
            throw new RuntimeException("文本纠错失败: " + e.getMessage(), e);
        }
    }
} 